<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Base\CommonPoolMethod;
use App\Service\Doctor\DoctorService;

class CommandTestService extends Command
{
    use CommonPoolMethod;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test:service';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '测试service单例和实例';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->info("test service beginning");
        // 1.测试单例
        $this->info("singleton begin time " . time());
        for ($x=0; $x<=10000; $x++)
        {
            $doctor = $this->service('Doctor\Doctor')->getDoctorById(2);
//            $this->info("singleton doctor " . $doctor->id . ' ' . $doctor->name);
        }
        $this->info("singleton end time " . time());

        // 2.测试实例
        $this->info("instance begin time " . time());
        for ($x=0; $x<=10000; $x++)
        {
            $doctorService = new DoctorService();
            $doctor = $doctorService->getDoctorById(2);
//            $this->info("instance doctor " . $doctor->id . ' ' . $doctor->name);
        }
        $this->info("instance begin time " . time());

        $this->info("test service ending");
    }
}
